package com.jrh.dal;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jrh.domain.common.Page;
import com.jrh.domain.entity.Atlas;

/**
 * 美图集DAO
 * 
 * @author jasen.hsu.cn@gmail.com 2012-7-23 下午12:48:28
 */
public class AtlasDao extends BaseDao<Atlas> {

    public AtlasDao(){
        this.namespace = "jrh.single.atlas";
    }

    @SuppressWarnings("unchecked")
    public Page<Atlas> list(Atlas atlas, Integer start, Integer pageSize) {
        @SuppressWarnings("static-access")
        Map<String, Object> map = this.getPageMap(start, pageSize);
        if (atlas != null) {
            map.put("name", atlas.getName());
            map.put("style", atlas.getStyle());
            map.put("category", atlas.getCategory());
        }
        List<Atlas> atlases = (List<Atlas>) sqlMapClientTemplate.queryForList(namespace + "." + "list", map);
        Integer count = (Integer) sqlMapClientTemplate.queryForObject(namespace + "." + "list_count", map);
        return new Page<Atlas>(atlases, start, pageSize, count);
    }

    /**
     * 取上一条,该实现排序号不能相等
     * 
     * @param id
     * @param style
     * @param cat
     * @return
     */
    public Atlas loadPrevious(Long id, Long style, Long cat) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        map.put("style", style);
        return (Atlas) sqlMapClientTemplate.queryForObject(namespace + "." + "loadPrevious", map);
    }

    /**
     * 取下一条,该实现排序号不能相等
     * 
     * @param id
     * @param style
     * @param cat
     * @return
     */
    public Atlas loadNext(Long id, Long style, Long cat) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        map.put("style", style);
        return (Atlas) sqlMapClientTemplate.queryForObject(namespace + "." + "loadNext", map);
    }
}
